﻿

using DKE_Kinect.Entwicklung.Core;
using Microsoft.Xna.Framework;

namespace DKE_Kinect.Entwicklung.Kinect.GestureEvents
{
    /// <summary>
    /// Klasse, die Gesten der Hand bereitstellt
    /// </summary>
    /// 
    public class HandGestures : GestureEvent
    {
        /// <summary>
        /// Mindestabstand vom Referenzpunkt für Gestenauslösung (Abstand Hand zu Ellenbogen)
        /// </summary>
        private float pMinDistance;

        /// <summary>
        /// Konstruktor für Gesten der Hand
        /// </summary>
        public HandGestures()
        {
        }

        /// <summary>
        /// Initialisiert Hand-Gesten
        /// </summary>
        /// <param name="_Hand">Jeweilige Hand</param>
        /// <param name="_Elbow">Ellenbogen der jeweiligen Handseite</param>
        public void LookFor(Vector3 _Hand, Vector3 _Elbow, float Factor)
        {
            Vector3 Reference = StateManager.ReferencePoint;

            pMinDistance = (_Hand - _Elbow).Length() * Factor; //Minimale Distanz

            // Left
            if (_Hand.X < (Reference.X - pMinDistance))
            {
                // UpperLeft
                if (_Hand.Y < (Reference.Y - pMinDistance))
                {
                    //EVENT
                    OnGestureEvent(new GestureEventArgs(Gestures.SwipeUpperLeft, StateManager.CurrMode));

                    return;
                }
                // LowerLeft
                else if (_Hand.Y > (Reference.Y + pMinDistance))
                {
                    //EVENT
                    OnGestureEvent(new GestureEventArgs(Gestures.SwipeLowerLeft, StateManager.CurrMode));
                    return;
                }

                //EVENT
                OnGestureEvent(new GestureEventArgs(Gestures.SwipeLeft, StateManager.CurrMode));
                return;
            }


            // Right
            if (_Hand.X > (Reference.X + pMinDistance))
            {
                // UpperRight
                if (_Hand.Y < (Reference.Y - pMinDistance))
                {
                    //EVENT
                    OnGestureEvent(new GestureEventArgs(Gestures.SwipeUpperRight, StateManager.CurrMode));
                    return;
                }
                // LowerRight
                else if (_Hand.Y > (Reference.Y + pMinDistance))
                {
                    //EVENT
                    OnGestureEvent(new GestureEventArgs(Gestures.SwipeLowerRight, StateManager.CurrMode));
                    return;
                }

                //EVENT
                OnGestureEvent(new GestureEventArgs(Gestures.SwipeRight, StateManager.CurrMode));
                return;
            }

            // Up
            if (_Hand.Y < (Reference.Y - pMinDistance))
            {
                //EVENT
                OnGestureEvent(new GestureEventArgs(Gestures.SwipeUp, StateManager.CurrMode));
                return;
            }

            // Down
            if (_Hand.Y > (Reference.Y + pMinDistance))
            {
                //EVENT
                OnGestureEvent(new GestureEventArgs(Gestures.SwipeDown, StateManager.CurrMode));
                return;
            }

        }

    }
}
